# # 首先，将PyOfficeRobot模块导入到我们的代码块中。
# from PyOfficeRobot.core.WeChatType import *

# # 获取当前微信客户端
# wx = WeChat()
# # 获取会话列表
# list = wx.GetSessionList()
# # print(list)
# # 向某人发送消息（以`文件传输助手`为例）
# msg = '你好~我是程序员晚枫，全网同名，感谢点赞 + 转发'
# who = '文件传输助手'
# wx.ChatWith(who)  # 打开`文件传输助手`聊天窗口
# # for i in range(10):
# wx.SendMsg(msg)  # 向`文件传输助手`发送消息：你好~

# wx.GetAllMessage()

#############################################

# # 首先，将PyOfficeRobot模块导入到我们的代码块中。
# import PyOfficeRobot

# PyOfficeRobot.chat.send_message(who='文件传输助手', message='你好')

#############################################
import sys
import uiautomation as auto

# GetFirstChildControl() GetLastChildControl()
# GetPreviousSiblingControl() GetNextSiblingControl()
# GetParentControl() GetChildren()
# uia.SetGlobalSearchTimeout(0) GetRuntimeId() uia.SetGlobalSearchTimeout(10.0)
# ClassName BoundingRectangle.height()


def isStartStatus(awc):
    # 是否启动状态
    if len(awc.ButtonControl(Name='最小化').GetParentControl().GetPreviousSiblingControl().GetChildren()) == 3:
        return True
    else:
        return False


def getSelfName(awc):
    # 获取本人昵称
    return awc.ButtonControl(Name='通讯录').GetParentControl().GetFirstChildControl().Name


def isLookMore(awc):
    # 是否有查看更多按钮
    if awc.GetFirstChildControl().Name == '查看更多消息':
        return True
    else:
        return False


def isGropyChat(awc):
    # 是否群组聊天
    # auto.SetGlobalSearchTimeout(0)
    res = [c for c, d in auto.WalkControl(awc) if isinstance(c, auto.ButtonControl) and c.Name == '直播']
    if len(res) != 1:
        return False
    else:
        return res[0]
    # auto.SetGlobalSearchTimeout(10.0)


def isSingleChat(awc):
    # 是否个人聊天
    res = [c for c, d in auto.WalkControl(awc) if isinstance(c, auto.ButtonControl) and c.Name == '视频聊天']
    if len(res) != 1:
        return False
    else:
        return res[0]


def isSubscriptionList(awc):
    # 订阅号列表
    res = [c for c, d in auto.WalkControl(awc) if isinstance(c, auto.ButtonControl) and (c.Name == '列表模式' or c.Name == '卡片模式')]
    if len(res) != 1:
        return False
    else:
        return res[0]


def getCurMsg(awc):
    # 获取当前会话的聊天记录
    timeHeight = 42  # 日期时间
    sysInfoHeight = 41  # 系统提醒 以下为最新消息 查看更多消息
    msgTypes = ['[文件]', '[图片]', '[视频]', '[音乐]', '[链接]']
    weekList = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]

    lc = awc.ListControl(Name='消息')

    # isLookMore(lc)
    # 日期时间判断
    # lc.WheelUp(wheelTimes=60, waitTime=0.1)#向上滚动
    for v in lc.GetChildren():        
        pass
        if v.Name in msgTypes: # 过滤非文字信息
            continue
        if '撤回了一条消息' in v.Name: # 过滤撤销信息
            continue

        print(v.Name)


wc = auto.WindowControl(ClassName='WeChatMainWndForPC')
# wc.SetTopmost(True)
# wc.SetActive()

# res = [c for c, d in auto.WalkControl(wc) if isinstance(c, auto.ButtonControl) and c.Name == '查看更多消息']
# print(res)

getCurMsg(wc)

# res = wc.ListControl(Name='会话')
# list = res.ListItemControl()
# print(res,list,list.GetNextSiblingControl())

# ec = wc.EditControl(Name='输入')
# print(ec)
# # ec.Click()
# ec.SendKeys('你好啊！')
# wc.ButtonControl(Name='sendBtn').Click()
